package com.example.as_sum.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import com.example.as_sum.activity.BaseActivity;

public abstract class BaseFragment extends RootFragment {
    @Override
    public void onAttach(Activity activity) {
        bContext= (BaseActivity) activity;
        super.onAttach(activity);
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        setParam();
        addListener();
        loadUIData();
    }
    protected BaseActivity bContext;
    /**
     *
     * @param view
     * 你可以在这里初始化一些View
     */
    public abstract void initView(View view);
    /**
     *
     *
     * 你可以在这里增加一些监听
     */
    public abstract void addListener();
    /**
     *
     *
     * 你可以在这里设置一些参数
     */
    public abstract void setParam();

    public abstract Handler getUIHandler();
    protected abstract void loadUIData();
    @Override
    public void onDestroy() {
        Handler handler=getUIHandler();
        if(handler!=null){
            handler.removeCallbacksAndMessages(null);
        }
        super.onDestroy();
    }
}
